<?php
/*
Plugin Name: Collapsible Categories Widget
Plugin URI: http://blog.lioux.com/index.php/2007/11/16/collapsible-categories-widget
Description: Allows for widget-based collapsible categories, based on the "List Expander" written by Alan Grakalic at cssglobe.com.
Version: 1.1
Author: Leo Jackson
Author URI: http://www.lioux.com
*/

/*  Copyright 2007 Leo Jackson (email: leo.jackson@gmail.com)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    this program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 03110-1301  USA
*/

function col_cats_init() {

function col_cats_css() {
	$blog_url = get_bloginfo('url');
	echo '<link href="'.$blog_url.'/wp-content/plugins/col_cats/col_cats.css" rel="stylesheet" type="text/css" media="screen" />';
	echo '<script type="text/javascript" src="'.$blog_url.'/wp-content/plugins/col_cats/col_cats.js"></script>';
}

function col_cats_widget($args) {
	extract($args);
	$options = get_option('col_cats_widget');
	$c = $options['count'] ? '1' : '0';
	$title = empty($options['title']) ? __('Categories') : $options['title'];
	$exclude = empty($options['exclude']) ? __('') : $options['exclude'];
	echo $before_widget;
	echo $before_title.$title.$after_title;
?>
<ul class="col_cats">

<?php 
$args='title_li=&orderby=name&show_count='.$c.'&exclude='.$exclude;
wp_list_categories($args); ?>
</ul>
<?php
	echo $after_widget;
}

function col_cats_widget_control() {
	$options = $newoptions = get_option('col_cats_widget');
	if ( $_POST['categories-submit'] ) {
		$newoptions['count'] = isset($_POST['categories-count']);
		$newoptions['title'] = strip_tags(stripslashes($_POST['categories-title']));
		$newoptions['exclude'] = strip_tags(stripslashes($_POST['exclude-catagories']));
	}
	if ( $options != $newoptions ) {
		$options = $newoptions;
		update_option('col_cats_widget', $options);
	}
	$count = $options['count'] ? 'checked="checked"' : '';
	$title = wp_specialchars($options['title']);
	$exclude = wp_specialchars($options['exclude']);
?>
			<p><label for="categories-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="categories-title" name="categories-title" type="text" value="<?php echo $title; ?>" /></label></p>
            
            <p><label for="exclude-catagories"><?php _e('Exclude-ID:'); ?> <input style="width: 230px;" id="exclude-catagories" name="exclude-catagories" type="text" value="<?php echo $exclude; ?>" /></label></p>
            
			<p style="text-align:right;margin-right:40px;"><label for="categories-count">Show post counts <input class="checkbox" type="checkbox" <?php echo $count; ?> id="categories-count" name="categories-count" /></label></p>
			<input type="hidden" id="categories-submit" name="categories-submit" value="1" />
<?php
}

add_action ('wp_head','col_cats_css');

register_sidebar_widget('Collapsible Categories','col_cats_widget');
register_widget_control('Collapsible Categories','col_cats_widget_control');

}

add_action ('plugins_loaded','col_cats_init');

?>
